<pre><code class="language-csharp"></code></pre>

private void GetAllControls(Control container, StringBuilder sb)
{
    foreach (Control c in container.Controls)
    {
        if (!string.IsNullOrEmpty(c.Text))
            sb.AppendLine($"{c.Name} ({c.GetType().Name}): {c.Text}");
        
        if (c.HasChildren)
            GetAllControls(c, sb);
    }
}